from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入下拉框操作类
from selenium.webdriver.support.select import Select

driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(20)
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/register.html'
driver.get(url)

# 下拉框操作
# sleep(3)
# driver.find_element(By.CSS_SELECTOR, '[value="sh"]').click()
# sleep(3)
# driver.find_element(By.CSS_SELECTOR, '[value="gz"]').click()

# 2.定位要操作的下拉框元素，实例化下拉框对象
element = driver.find_element(By.CSS_SELECTOR, '#select')
s = Select(element)
# 3.通过下拉选项的下标切换
# sleep(3)
# s.select_by_index(1)
# sleep(3)
# s.select_by_index(2)
# 4.通过value 属性切换
# sleep(3)
# s.select_by_value('sh')
# sleep(3)
# s.select_by_value('gz')
# 5.通过显示文本切换
sleep(3)
s.select_by_visible_text('上海')
sleep(3)
s.select_by_visible_text('广州')

sleep(3)
driver.quit()